<?php
/**
 * Created by PhpStorm
 * User: Jhinwy
 * Date: 5/10/24
 * Time: 10:35 AM
 */

namespace app\adminapi\lists\shield;

use app\adminapi\lists\BaseAdminDataLists;
use app\common\lists\ListsSearchInterface;
use app\common\model\shield\BlackIp;


/**
 * 黑名单IP
 *
 * Class OrderLists
 * @package app\adminapi\lists
 */
class BlackIpLists extends BaseAdminDataLists implements ListsSearchInterface
{


    /**
     * 搜索条件
     *
     * @return array
     */
    public function setSearch(): array
    {
        if ($this->request->get('ip_address', '')) {
            return [
                '=' => ['ip_address'],
            ];
        } else {

            return [];
        }
    }


    public function queryWhere(): array
    {
        return [];
    }


    public function count(): int
    {
        return BlackIp::count();
    }


    /**
     * 获取列表
     *
     * @return array
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\DbException
     * @throws \think\db\exception\ModelNotFoundException
     */
    public function lists(): array
    {
        return BlackIp::field('id, ip_address, create_time, update_time')
            ->where($this->searchWhere)
            ->order('create_time', 'desc')
            ->limit($this->limitOffset, $this->limitLength)
            ->select()
            ->toArray();
    }
}
